﻿using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 剧情设计器2._0
{
    public partial class SettingTypesManager : Form
    {
        public SettingTypesManager()
        {
            InitializeComponent();
        }

        void UpdateDisplay()
        {
            listBox_types.Items.Clear();
            if (Common.setting_types.Count == 0) return;
            for (int i = 0; i < Common.setting_types.Count; i++)
            {
                listBox_types.Items.Add(Common.setting_types[i]);
            }
        }

        private void SettingTypesManager_Load(object sender, EventArgs e)
        {
            UpdateDisplay();
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            Common.setting_types.Clear();
            foreach (string type in listBox_types.Items)
            {
                Common.setting_types.Add(type);
            }
            Close();
        }

        private void btn_add_Click(object sender, EventArgs e)
        {
            string type = Interaction.InputBox("请输入新的类型:", "创建类型", "");
            if (type == "") return;
            if (!Common.inList(type, Common.setting_types))
            {
                Common.setting_types.Add(type);
                UpdateDisplay();
            }
            else MessageBox.Show(string.Format("类型 {0} 已存在！", type), "创建类型");
        }

        private void btn_del_Click(object sender, EventArgs e)
        {
            int idx = listBox_types.SelectedIndex;
            if (idx < 0) return;
            if (MessageBox.Show(string.Format("确定要删除类型 {0} 吗", Common.setting_types[idx]), "删除", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Common.setting_types.RemoveAt(idx);
                UpdateDisplay();
            }
        }
    }
}
